import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/Login'
import home from '../views/Home'
import forgetPasswd from '../views/ForgetPasswd'
import faceCheck from '../views/FaceCheck'
import payPage from '../views/PayPage'
import areaList from '../components/area/AreaList'
import courseList from '../components/course/CourseList'
import courseOrder from '../components/course/CourseOrder'
import employeeList from '../components/employee/EmployeeList'
import faceRegister from "@/components/employee/FaceRegister";
import workAttendance from '../components/employee/WorkAttendance'
import equipList from '../components/equip/EquipList'
import equipOverhaul from '../components/equip/EquipOverhaul'
import goodsList from '../components/goods/GoodsList'
import goodsOrder from '../components/goods/GoodsOrder'
import memberList from '../components/member/MemberList'
import newOrder from '../components/order/NewOrder'
import orderData from '../components/order/OrderData'
import orderList from '../components/order/OrderList'
import unsettled from '../components/pay/Unsettled'
import pointsMall from '../components/integral/PointMall'
import pointSelect from '../components/integral/PointSelect'
import capitalHome from "@/components/capital/capitalHome";
import TopCapital from "@/components/capital/TopCapital";
import MonthCapital from "@/components/capital/MonthCapital";
import TodayCapital from "@/components/capital/TodayCapital";

import {Message} from "element-ui";
import coachList from "@/components/coach/CoachList.vue";
import reservationList from "@/components/order/ReservationList.vue";
import suggestionList from "@/components/suggestion/SuggestionList.vue";


Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/home',
    },
    {
        path: '/home',
        component: home,
        redirect: '/orderData',
        children: [
            //订单
            {
                path: '/newOrder',
                component: newOrder
            },
            {
                path: '/orderData',
                component: orderData
            },
            {
                path: '/orderList',
                component: orderList
            },
            //会员
            {
                path: '/memberList',
                component: memberList
            },
            //员工
            {
                path: '/employeeList',
                component: employeeList
            },
            {
                path: '/workAttendance',
                component: workAttendance
            },
            {
                path: '/faceRegister',
                component: faceRegister
            },
            {
                path: '/coachList',
                component: coachList
            },
            {
                path: '/reservationList',
                component: reservationList
            },
            {
                path: '/equipList',
                component: equipList
            },
            {
                path: '/equipOverhaul',
                component: equipOverhaul
            },
            {
                path: '/goodsList',
                component: goodsList
            },
            {
                path: '/goodsOrder',
                component: goodsOrder
            },
            {
                path: '/areaList',
                component: areaList
            },
            {
                path: '/courseList',
                component: courseList
            },
            {
                path: '/courseOrder',
                component: courseOrder
            },
            {
                path: '/unsettled',
                component: unsettled
            },
            {
                path: '/pointsMall',
                component: pointsMall
            },
            {
                path: '/pointSelect',
                component: pointSelect
            },
            {
                path: '/suggestionList',
                component: suggestionList
            },
            {
                path: '/capitalHome',
                component: capitalHome,
                redirect: '/capitalHome/topCapital',
                children: [
                    {
                        path: '/capitalHome/topCapital',
                        component: TopCapital
                    },
                    {
                        path: '/capitalHome/monthCapital',
                        component: MonthCapital
                    },
                    {
                        path: '/capitalHome/todayCapital',
                        component: TodayCapital
                    }
                ]
            }
        ]
    },
    {
        path: '/login',
        component: login
    }, {
        path: '/forgetPasswd',
        component: forgetPasswd
    },
    {
        path: '/faceCheck',
        component: faceCheck
    },
    {
        path: '/payPage',
        component: payPage
    },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})
router.beforeEach((to, from, next) => {
    if (to.path === '/login' || to.path === '/register' || to.path === '/forgetPasswd') {
        next()
    } else {
        let accountToken = localStorage.getItem('token');
        if (accountToken == null || accountToken == '') {
            Message.error("无权限，请登录!")
            return next('/login');
        } else {
            next();
        }
    }
})


export default router
